#include "NewAddressTab.h"
#include "common.hpp"
#include<QLabel>
#include<QPushButton>
#include<QVBoxLayout>
#include<QHBoxLayout>
#include"AddDialog.h"
#include<QLineEdit>
#include<QTextEdit>


NewAddressTab::NewAddressTab(QWidget* parent )
	:QWidget(parent)
{
	Q_UNUSED(parent);

	descriptionLabel_ = new QLabel(tr("There are currently no contacts in your address book. "
				"\nClick Add to add new contacts."));

	addButton_ = new QPushButton(tr("Add"));

	connect(addButton_ , &QAbstractButton::clicked , this , &NewAddressTab::addEntry);

	mainLayout_ = new QVBoxLayout;
	mainLayout_->addWidget(descriptionLabel_);
	mainLayout_->addWidget(addButton_ , 0 , Qt::AlignCenter);

	setLayout(mainLayout_);
}

NewAddressTab::~NewAddressTab()
{
	delete_ptr_if(descriptionLabel_);
	delete_ptr_if(addButton_);
	delete_ptr_if(mainLayout_);
}

void NewAddressTab::addEntry()
{
	AddDialog dlg;

	if(dlg.exec())
	{
        QString name = dlg.nameText_->text();
        QString address = dlg.addressText_->toPlainText();

		emit sendDetails(name ,address);
	}
}
